/**
 * 资源相关请求模块
 */

import request from '@/utils/request'

interface GetResourcePages {
  id?: number;
  name?: string;
  startCreateTime?: string;
  url?: string;
  categoryId?: number | null;
  endCreateTime?: string;
  current?: number;
  size?: number;
}

interface AllocateRoleResources {
  roleId: number | string;
  resourceIdList?: number[];
}

export interface SaveOrUpdateInter {
  id?: number;
  name: string;
  url: string;
  categoryId: number;
  description?: string;
}

export const getResourcePages = (data: GetResourcePages) => {
  return request({
    method: 'POST',
    url: '/boss/resource/getResourcePages',
    data
  })
}

export const deteleResource = (id: number) => {
  return request({
    method: 'DELETE',
    url: `/boss/resource/${id}`
  })
}

export const saveOrUpdate = (data: SaveOrUpdateInter) => {
  return request({
    method: 'POST',
    url: '/boss/resource/saveOrUpdate',
    data
  })
}

/** 给角色分配资源 */
export const allocateRoleResources = (data: AllocateRoleResources) => {
  return request({
    method: 'POST',
    url: '/boss/resource/allocateRoleResources',
    data
  })
}

/** 获取角色拥有的资源列表 */
export const getRoleResources = (roleId: string | number) => {
  return request({
    method: 'GET',
    url: '/boss/resource/getRoleResources',
    params: {
      roleId
    }
  })
}

/** 获取所有资源 */
export const getResourceNodeList = () => {
  return request({
    method: 'GET',
    url: '/boss/resource/getAll'
  })
}
